  <template>
  <common-layout>
    <div class="top">
      <div class="header">
        <img alt="logo" class="logo" src="@/assets/img/logo.png" />
        <span class="title">儿科渠道管理</span>
      </div>
    </div>
    <div class="login">
      <a-form @submit="onSubmit" :form="form">
        <a-tabs
          size="large"
          :tabBarStyle="{ textAlign: 'center' }"
          style="padding: 0 2px"
        >
          <a-tab-pane tab="账户密码登录" key="1">
            <a-alert
              type="error"
              :closable="true"
              v-show="error"
              :message="error"
              showIcon
              style="margin-bottom: 24px"
            />
            <a-form-item>
              <a-input
                autocomplete="autocomplete"
                size="large"
                placeholder="请输入手机号"
                v-decorator="[
                  'name',
                  {
                    rules: [
                      {
                        required: true,
                        message: '请输入账户名',
                        whitespace: true,
                      },
                    ],
                  },
                ]"
              >
                <a-icon slot="prefix" type="user" />
              </a-input>
            </a-form-item>
            <a-form-item>
              <a-input
                size="large"
                placeholder="请输入密码"
                autocomplete="autocomplete"
                type="password"
                v-decorator="[
                  'password',
                  {
                    rules: [
                      {
                        required: true,
                        message: '请输入密码',
                        whitespace: true,
                      },
                    ],
                  },
                ]"
              >
                <a-icon slot="prefix" type="lock" />
              </a-input>
            </a-form-item>
          </a-tab-pane>
          
        </a-tabs>
        <a-form-item>
          <a-button
            style="width: 100%; margin-top: 24px"
            size="large"
            htmlType="submit"
            type="primary"
            >登录</a-button
          >
        </a-form-item>
        <div>
          
        </div>
      </a-form>
      <div>
        <router-link style="float: left" to="/register"
            >注册账户</router-link
          >
        <a style="float: right" @click="handleForget">忘记密码</a>
      </div>
    </div>
    <a-modal
      title="修改密码"
      v-model="visible"
      :destroyOnClose="true"
      @ok="closeModal"
      :footer="null"
    >
      <ForgetPassword />
    </a-modal>
  </common-layout>
</template>
 
<script>
// 账号15961858835
// 密码 123456
// 账号18362375700
// 密码 234567

import CommonLayout from "@/layouts/CommonLayout";
import { getToken } from "@/services/user";
import { login } from "../../services/user";
import { getUser } from "../../services/dataSource";
import { setAuthorization } from "@/utils/request";
import ForgetPassword from "../login/ForgetPassword.vue";
// import { loadRoutes } from "@/utils/routerUtil";
import { mapMutations } from "vuex";
export default {
  name: "Login",
  components: {
    CommonLayout,
    ForgetPassword
  },
  data() {
    return {
      // logging: false,
      error: "",
      form: this.$form.createForm(this),
      visible: false,
    };
  },
  computed: {
    systemName() {
      return this.$store.state.setting.systemName;
    },
  },
  methods: {
    swithModel(e) {
      this.visible = true;
    },
    closeModal(e) {
      this.visible = false;
    },
    ...mapMutations("account", ["setUser", "setPermissions", "setRoles"]),
    onSubmit(e) {
      e.preventDefault();
      this.form.validateFields((err) => {
        if (!err) {
          // this.logging = true;
          const mobile = this.form.getFieldValue("name");
          const password = this.form.getFieldValue("password");
          // const mobile = 13911111111;
          // const password = 123456;
          getToken("admin", "123qwe")
            .then((res) => {
              window.localStorage.setItem(
                "Authorization",
                res.data.result.accessToken
              );
              setAuthorization({
                token: res.data.result.accessToken,
              });
              login(mobile, password).then(this.afterLogin);
            })
            .catch((err) => {
              console.log(err);
            });

          // login(name, password);
          // .then((res) => {
          //   if (res.data && res.data.status === 0) {
          //     const token = res.headers["access-token"];
          //     window.sessionStorage.setItem("token", token);
          //     this.$router.push("/dashboard");
          //   } else {
          //     //此处需要根据status来判断登陆具体错误情况
          //     this.$message.info("登陆失败,账号密码不符");
          //     me.loading = false;
          //   }
          //   console.log(res);
          //   console.log(res.headers["access-token"]);
          // })
          // .catch((err) => {
          //   console.log(err);
          // });
        }
      });
    },
    afterLogin(res) {
      window.localStorage.setItem("id", res.data.result.id);
      window.localStorage.setItem("disbName", res.data.result.disbName);
      window.localStorage.setItem("disbNO", res.data.result.disbNO);
      window.localStorage.setItem("mobile", res.data.result.mobile);
      window.localStorage.setItem("bankAccount", res.data.result.bankAccount);
      window.localStorage.setItem("distype", res.data.result.distype);
      const test = localStorage.getItem("bankAccount");
      if (res.data.result.memberID == null) {
        res.data.result.memberID = 1;
      }
      window.localStorage.setItem("memberID", res.data.result.memberID);
      if (res.data.result.enabled != true && res.data.result.isApprve != true) {
        this.$message.info("过期或审核未通过");
      } else {
        this.$router.push("/dashboard/form");
      }
      // if (res.data && res.data.status === 0) {
      //   const token = res.headers["access-token"];
      //   // window.localStorage.setItem("token", token);

      //   setAuthorization({
      //     token: token,
      //   });
      // } else {
      //   //此处需要根据status来判断登陆具体错误情况
      //   this.$message.info("登陆失败,账号密码不符");
      //   me.loading = false;
      // }
      // console.log(res);
      // console.log(res.headers["access-token"]);

      // getUser(res.data.result.userId)
      //   .then((res) => {
      //     console.log(res);
      //     window.localStorage.setItem("name", res.data.result.name);
      //   })
      //   .catch((err) => {
      //     console.log(err);
      //   });
      // this.$router.push("dashboard");
    },
    handleForget() {
      this.$router.push("/forgetPassword");
    },
  },
  created() {},
};
</script>

<style lang="less" scoped>
.common-layout {
  .top {
    text-align: center;
    margin-top: 8.125rem;
    .header {
      height: 44px;
      line-height: 44px;
      a {
        text-decoration: none;
      }
      .logo {
        height: 44px;
        vertical-align: top;
        margin-right: 16px;
      }
      .title {
        font-size: 33px;
        color: @title-color;
        font-family: "Myriad Pro", "Helvetica Neue", Arial, Helvetica,
          sans-serif;
        font-weight: 600;
        position: relative;
        top: 2px;
      }
    }
    .desc {
      font-size: 14px;
      color: @text-color-second;
      margin-top: 12px;
      margin-bottom: 40px;
    }
  }
  .login {
    width: 368px;
    margin: 0 auto;
    @media screen and (max-width: 576px) {
      width: 95%;
    }
    @media screen and (max-width: 320px) {
      .captcha-button {
        font-size: 14px;
      }
    }
    .icon {
      font-size: 24px;
      color: @text-color-second;
      margin-left: 16px;
      vertical-align: middle;
      cursor: pointer;
      transition: color 0.3s;

      &:hover {
        color: @primary-color;
      }
    }
  }
}
.ant-input {
  padding-left: 40px;
}
</style>
